package com.thinkinjava.typeinformation;

/**
 * @Description  静态代理
 * @Author
 * @Date 2019/10/5 21:43
 **/
interface Interface{
    void doSomething();
    void someThingElse(String string);
}

class RealObject implements Interface{

    @Override
    public void doSomething() {
        System.out.println("doSomething");
    }

    @Override
    public void someThingElse(String string) {
        System.out.println("someThingElse:" + string);
    }
}

class SimpleProxy implements Interface{
    private Interface proxied;

    public SimpleProxy(Interface proxied) {
        this.proxied = proxied;
    }

    @Override
    public void doSomething() {
        System.out.println("SimpleProxy doSomething");
        proxied.doSomething();
    }

    @Override
    public void someThingElse(String string) {
        System.out.println("SimpleProxy someThingElse" + string);
        proxied.someThingElse(string);
    }
}

class SimpleProxyDemo{
    public static void consumer(Interface iface){
        iface.doSomething();
        iface.someThingElse("bbbbbb");
    }

    public static void main(String[] args) {
        consumer(new RealObject());
        consumer(new SimpleProxy(new RealObject()));
    }
}